<?php
/**
 * Function Admin
 */
if ( ! function_exists( 'can' ) ) {
    /**
     * 验证后台权限
     * @param string $path 路径
     * @author zx
     * @date 2020-01-02
     * @throws \app\exceptions\OrdinaryException
     * @return boolean
     */
    function can( string $path ) {
        $info = \app\admin\service\Token::decode(session('token'));
        $user = (array)$info['data']['userInfo'];
        if ( $user['type'] == 1 ) {
            return true;
        }
        try {
            return app('rbac')->can($path);
        } catch ( \think\Exception $exception ) {
            throw new \app\exceptions\OrdinaryException($exception->getMessage());
        }
    }
}